.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "SAMBAMBA\-VIEW" "1" "June 2016" "" ""
.
.SH "NAME"
\fBsambamba\-view\fR \- tool for extracting information from SAM/BAM/CRAM files
.
.SH "SYNOPSIS"
\fBsambamba view\fR \fIOPTIONS\fR <input\.bam | input\.sam | input\.cram> [region1 [\.\.\.]]
.
.SH "DESCRIPTION"
\fBsambamba view\fR allows to efficiently filter SAM/BAM/CRAM files for alignments satisfying various conditions, as well as access its SAM header and information about reference sequences\. In order to make these data readily available for consumption by scripts in Perl/Python/Ruby, JSON output is provided\.
.
.P
By default, the tool expects BAM file as an input\. In order to work with CRAM, specify \-C and for SAM, specify \fB\-S\fR|\fB\-\-sam\-input\fR as a command\-line option, the tool does NOT try to guess file format from the extension\. Beware that when reading SAM, the tool will skip tags which don\'t conform to the SAM/BAM specification, and set invalid fields to their default values\.
.
.SH "FILTERING"
Filtering is presented in two ways\. First, you can specify a condition with \fB\-F\fR option, using a special language for filtering, described at
.
.P
https://github\.com/lomereiter/sambamba/wiki/%5Bsambamba\-view%5D\-Filter\-expression\-syntax
.
.P
Second, if you have an indexed BAM file, several regions can be specified as well\. The syntax for regions is the same as in samtools: \fIchr\fR:\fIbeg\fR\-\fIend\fR where \fIbeg\fR and \fIend\fR are 1\-based start and end of a closed\-end interval on the reference \fIchr\fR\.
.
.SH "JSON"
Alignment record JSON representation is a hash with keys \'qname\', \'flag\', \'rname\', \'pos\', \'mapq\', \'cigar\', \'rnext\', \'qual\', \'tags\', e\.g\.
.
.P
{"qname":"EAS56_57:6:190:289:82","flag":69,"rname":"chr1","pos":100,
.
.br
"mapq":0,"cigar":"*","rnext":"=","pnext":100,"tlen":0,
.
.br
"seq":"CTCAAGGTTGTTGCAAGGGGGTCTATGTGAACAAA",
.
.br
"qual":[27,27,27,22,27,27,27,26,27,27,27,27,27,27,27,27,23,26,26,27,
.
.br
22,26,19,27,26,27,26,26,26,26,26,24,19,27,26],"tags":{"MF":192}}
.
.P
JSON representation mimics SAM format except quality is given as an array of integers\.
.
.P
Postprocessing JSON output is best accomplished with https://stedolan\.github\.io/jq/
.
.P
The output is one line per read, for building a proper JSON array pipe the output into \fBjq \-\-slurp\fR\.
.
.SH "OPTIONS"
.
.TP
\fB\-F\fR, \fB\-\-filter\fR=\fIFILTER\fR
Set custom filter for alignments\.
.
.TP
\fB\-f\fR, \fB\-\-format\fR=\fIFORMAT\fR
Specify output format\. \fIFORMAT\fR must be one of sam, bam, cram, or json (in lowercase)\. Default is SAM\.
.
.TP
\fB\-h\fR, \fB\-\-with\-header\fR
Print SAM header before reads\. This is always done for BAM output\.
.
.TP
\fB\-H\fR, \fB\-\-header\fR
Print only SAM header to STDOUT\. If \fIFORMAT\fR is sam or bam, its text version is printed, otherwise JSON object is written\.
.
.TP
\fB\-I\fR, \fB\-\-reference\-info\fR
Output to STDOUT reference sequence names and lengths in JSON (see \fIEXAMPLES\fR)\.
.
.TP
\fB\-L\fR, \fB\-\-regions\fR=\fIBEDFILE\fR
Intersect a file with regions specified in the BED file\.
.
.TP
\fB\-c\fR, \fB\-\-count\fR
Output to STDOUT only the number of matching records, \-hHI options are ignored\.
.
.TP
\fB\-v\fR, \fB\-\-valid\fR
Output only valid reads\.
.
.TP
\fB\-S\fR, \fB\-\-sam\-input\fR
Specify that the input is SAM file (default is BAM for all operations)\.
.
.TP
\fB\-C\fR, \fB\-\-cram\-input\fR
Specify that input is in CRAM format
.
.TP
\fB\-p\fR, \fB\-\-show\-progress\fR
Show progressbar in STDERR\. Works only for BAM files, and with no regions specified, i\.e\. only when reading full file\.
.
.TP
\fB\-l\fR, \fB\-\-compression\-level\fR=\fICOMPRESSION_LEVEL\fR
Set compression level for BAM output, a number from 0 to 9\.
.
.TP
\fB\-o\fR, \fB\-\-output\-filename\fR=\fIFILENAME\fR
Specify output filename (by default everything is written to STDOUT)\.
.
.TP
\fB\-t\fR, \fB\-\-nthreads\fR=\fINTHREADS\fR
Number of threads to use\.
.
.SH "EXAMPLES"
Print basic reference sequence information:
.
.IP "" 4
.
.nf

 $ sambamba view \-\-reference\-info ex1_header\.bam
 [{"name":"chr1","length":1575},{"name":"chr2","length":1584}]
.
.fi
.
.IP "" 0
.
.P
Count reads with mapping quality not less than 50:
.
.IP "" 4
.
.nf

 $ sambamba view \-c \-F "mapping_quality >= 50" ex1_header\.bam
 3124
.
.fi
.
.IP "" 0
.
.P
Count properly paired reads overlapping 100\.\.200 on chr1:
.
.IP "" 4
.
.nf

 $ sambamba view \-c \-F "proper_pair" ex1_header\.bam chr1:100\-200
 39
.
.fi
.
.IP "" 0
.
.P
Output header in JSON format:
.
.IP "" 4
.
.nf

 $ sambamba view \-\-header \-\-format=json ex1_header\.bam
 {"format_version":"1\.3","rg_lines":[],
  "sq_lines":[{"sequence_length":1575,"species":"","uri":"",
  "sequence_name":"chr1","assembly":"","md5":""},
  {"sequence_length":1584,"species":"","uri":"",
  "sequence_name":"chr2","assembly":"","md5":""}],
  "sorting_order":"coordinate","pg_lines":[]}
.
.fi
.
.IP "" 0
.
.SH "SEE ALSO"
For more information on the original samtools VIEW behaviour, check out the samtools documentation \fIhttp://samtools\.sourceforge\.net/samtools\.shtml\fR\.
